//
//  MSLNetworking.m
//  MSLNews
//
//  Created by lirenqiang on 16/6/12.
//  Copyright © 2016年 lirenqiang. All rights reserved.
//

#import "MSLNetworking.h"



@implementation MSLNetworking

+ (instancetype)sharedNetworking {
    static MSLNetworking * sharedNetworkingTool = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedNetworkingTool = [[self alloc] init];
    });
    
    return sharedNetworkingTool;
}

- (void)loadChannelViewData:(void (^)(id responseObject, NSError * error))finished {
    
    self.responseSerializer.acceptableContentTypes = [self.responseSerializer.acceptableContentTypes setByAddingObject:@"text/plain"];
    self.responseSerializer.acceptableContentTypes = [self.responseSerializer.acceptableContentTypes setByAddingObject:@"text/html"];
    
    [self GET:@"http://127.0.0.1/topic_news.json" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
//        NSLog(@"%@", responseObject);
        finished(responseObject, nil);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        finished(nil, error);
    }];
    
}

- (void)loadTableViewData:(NSString *)tid finished:(void(^)(id responseObject, NSError * error))finished {
    
    NSString * finalURL = [NSString stringWithFormat:@"http://c.m.163.com/nc/article/headline/%@/0-20.html", tid];
    
    [self GET:finalURL parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        finished(responseObject, nil);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        //
        finished(nil, error);
    }];
    
}


@end
